unit InternHttpClient_Unit;

interface

uses IdHTTP, SysUtils;

type
  TInternHttpClient = class(TObject)
  private
    { Private declarations }
    http: TIdHttp;
  public
    { Public declarations }
    function getNieuwsteVersie(kenmerk: String) : String;
    procedure AfterConstruction; override;
    procedure BeforeDestruction; override;
  end;

implementation

  {
    * getNieuwsteVersie
  }
  function TInternHttpClient.getNieuwsteVersie(kenmerk: String) : String;
  begin

    //nieuwste versie van TVScanner ophalen van TVScanner.nl
    try

      //connection timeout op 2 seconden instellen
      http.ConnectTimeout := 2000;

      //active versie van TVScanner ophalen, tevens kenmerk meesturen
      result := http.Get('http://www.tvscanner.nl/getActiveVersion.php?kenmerk=' + kenmerk);
    except
      on E: Exception do
        result := E.Message;
    end;
  end;

  {
    * AfterConstruction
  }
  procedure TInternHttpClient.AfterConstruction;
  begin

    //Http inialiseren
    http := TIdHTTP.Create(Nil);

    //redirects toestaan
    http.HandleRedirects := True;

    //cookies accepteren
    http.AllowCookies := true;
  end;

  {
    * BeforeDestruction
  }
  procedure TInternHttpClient.BeforeDestruction;
  begin

    //Http component vrijgeven
    if Assigned(http) then
      http.Free();
  end;

end.
